package com.zh.flowable.domain.dto;

import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;

/**
 * @author
 * @date 2025/8/21
 */
public class TaskWrapper {

    public static TaskDTO convertDTO(Task task) {
        TaskDTO dto = new TaskDTO();
        dto.setId(task.getId());
        dto.setName(task.getName());
        dto.setCategory(task.getCategory());
        dto.setFormKey(task.getFormKey());
        dto.setDescription(task.getDescription());
        dto.setPriority(task.getPriority());
        dto.setOwner(task.getOwner());
        dto.setAssignee(task.getAssignee());
        dto.setExecutionId(task.getExecutionId());
        dto.setState(task.getState());
        dto.setCreateTime(task.getCreateTime());
//        dto.setDelegationState(Optional.ofNullable(task.getDelegationState()).map(Enum::name).orElse(""));
        dto.setProcessInstanceId(task.getProcessInstanceId());
        dto.setProcessDefinitionId(task.getProcessDefinitionId());
        dto.setTaskDefinitionId(task.getTaskDefinitionId());
        dto.setTaskDefinitionKey(task.getTaskDefinitionKey());
        dto.setScopeId(task.getScopeId());
        dto.setSubScopeId(task.getSubScopeId());
        dto.setScopeType(task.getScopeType());
        dto.setScopeDefinitionId(task.getScopeDefinitionId());
        dto.setPropagatedStageInstanceId(task.getPropagatedStageInstanceId());
        dto.setInProgressStartTime(task.getInProgressStartTime());
        dto.setInProgressStartedBy(task.getInProgressStartedBy());
        dto.setClaimTime(task.getClaimTime());
        dto.setClaimedBy(task.getClaimedBy());
        dto.setSuspendedTime(task.getSuspendedTime());
        dto.setSuspendedBy(task.getSuspendedBy());
        dto.setInProgressStartDueDate(task.getInProgressStartDueDate());
        dto.setDueDate(task.getDueDate());
        dto.setParentTaskId(task.getParentTaskId());
        dto.setTenantId(task.getTenantId());

        return dto;
    }

    public static TaskDTO convertDTO(HistoricTaskInstance task) {
        var dto = new TaskDTO();
        dto.setId(task.getId());
        dto.setName(task.getName());
        dto.setCategory(task.getCategory());
        dto.setFormKey(task.getFormKey());
        dto.setDescription(task.getDescription());
        dto.setPriority(task.getPriority());
        dto.setOwner(task.getOwner());
        dto.setAssignee(task.getAssignee());
        dto.setExecutionId(task.getExecutionId());
        dto.setState(task.getState());
        dto.setCreateTime(task.getCreateTime());
//        dto.setDelegationState(Optional.ofNullable(task.getDelegationState()).map(Enum::name).orElse(""));
        dto.setProcessInstanceId(task.getProcessInstanceId());
        dto.setProcessDefinitionId(task.getProcessDefinitionId());
        dto.setTaskDefinitionId(task.getTaskDefinitionId());
        dto.setTaskDefinitionKey(task.getTaskDefinitionKey());
        dto.setScopeId(task.getScopeId());
        dto.setSubScopeId(task.getSubScopeId());

        return dto;
    }
}
